package com.ruoyi.web.controller.house;

import com.ruoyi.house.domain.WebmagicYear;
import com.ruoyi.house.service.IWebmagicYearService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 年度销售Controller
 * 
 * @author ruoyi
 * @date 2023-06-09
 */
@Controller
@RequestMapping("/house/year")
public class WebmagicYearController extends BaseController
{
    private String prefix = "house/year";

    @Autowired
    private IWebmagicYearService webmagicYearService;

    @RequiresPermissions("house:year:view")
    @GetMapping()
    public String year()
    {
        return prefix + "/year";
    }

    /**
     * 查询年度销售列表
     */
    @RequiresPermissions("house:year:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WebmagicYear webmagicYear)
    {
        startPage();
        List<WebmagicYear> list = webmagicYearService.selectWebmagicYearList(webmagicYear);
        return getDataTable(list);
    }

    /**
     * 导出年度销售列表
     */
    @RequiresPermissions("house:year:export")
    @Log(title = "年度销售", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WebmagicYear webmagicYear)
    {
        List<WebmagicYear> list = webmagicYearService.selectWebmagicYearList(webmagicYear);
        ExcelUtil<WebmagicYear> util = new ExcelUtil<WebmagicYear>(WebmagicYear.class);
        return util.exportExcel(list, "年度销售数据");
    }

    /**
     * 新增年度销售
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存年度销售
     */
    @RequiresPermissions("house:year:add")
    @Log(title = "年度销售", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WebmagicYear webmagicYear)
    {
        return toAjax(webmagicYearService.insertWebmagicYear(webmagicYear));
    }

    /**
     * 修改年度销售
     */
    @RequiresPermissions("house:year:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WebmagicYear webmagicYear = webmagicYearService.selectWebmagicYearById(id);
        mmap.put("webmagicYear", webmagicYear);
        return prefix + "/edit";
    }

    /**
     * 修改保存年度销售
     */
    @RequiresPermissions("house:year:edit")
    @Log(title = "年度销售", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WebmagicYear webmagicYear)
    {
        return toAjax(webmagicYearService.updateWebmagicYear(webmagicYear));
    }

    /**
     * 删除年度销售
     */
    @RequiresPermissions("house:year:remove")
    @Log(title = "年度销售", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(webmagicYearService.deleteWebmagicYearByIds(ids));
    }
}
